package com.scedu.springcloud.springcloud.controller;

import com.scedu.springcloud.springcloud.entity.CommonResult;
import com.scedu.springcloud.springcloud.entity.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderController {
    //public  static  final  String PAYMENT_URL="http://localhost:8081";
    // public  static  final  String PAYMENT_URL="http://CLOUD-PAYMENT-SERVICE";// eureka服务提供者的名称是大写
    public  static  final  String PAYMENT_URL="http://cloud-payment-service";// zookeeper服务提供者的名称是小写
    @Resource
    private RestTemplate restTemplate;

    @GetMapping(value = "consumer/create")
    public CommonResult create(Payment payment){
        CommonResult commonResult = restTemplate.postForObject(PAYMENT_URL + "/payment/create", payment, CommonResult.class);
        log.info(String.valueOf(commonResult));
        return commonResult;
    }

    @GetMapping(value = "consumer/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id){

        return  restTemplate.getForObject( PAYMENT_URL + "/payment/get/"+id, CommonResult.class);


    }
}
